/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import delta.emailer.EmailerLocal;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import utils.ConfigurationManager;

/**
 *
 * @author Svetlana Shikhutskaya
 */
public class Emailer implements Runnable{
    EmailerLocal emailer = lookupEmailerLocal();
    String email;
    String topic;
    String content;

    public Emailer(String email, String topic, String content){
        this.email=email;
        this.topic=topic;
        this.content=content;
    }
    public void run() {
        emailer.sendEmail(email, topic, content);
    }

    private EmailerLocal lookupEmailerLocal() {
        try {
            Context c = new InitialContext();
            return (EmailerLocal) c.lookup("java:global/Delta/Delta-ejb/Emailer!delta.emailer.EmailerLocal");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
